package com.example.candiates.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.candiates.domain.InterviewCandidates;
import com.example.candiates.mapper.InterviewCandidatesMapper;
import com.example.candiates.service.InterviewCandidatesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class InterviewCandidatesServiceImpl extends ServiceImpl<InterviewCandidatesMapper, InterviewCandidates> implements InterviewCandidatesService {

    @Autowired
    private InterviewCandidatesMapper interviewCandidatesMapper;
    @Override
    public Page<InterviewCandidates> selectInterviewCandidatesList(InterviewCandidates interviewCandidates, int pageNum, int pageSize) {
        QueryWrapper<InterviewCandidates> queryWrapper = new QueryWrapper<>();
        
        // 添加查询条件
        if (interviewCandidates != null) {
            if (interviewCandidates.getName() != null && !interviewCandidates.getName().trim().isEmpty()) {
                queryWrapper.eq("name", interviewCandidates.getName());
            }
            if (interviewCandidates.getPhone() != null && !interviewCandidates.getPhone().trim().isEmpty()) {
                queryWrapper.eq("phone", interviewCandidates.getPhone());
            }
            if (interviewCandidates.getPosition() != null && !interviewCandidates.getPosition().trim().isEmpty()) {
                queryWrapper.eq("position", interviewCandidates.getPosition());
            }
            if (interviewCandidates.getInterviewStatus() != null) {
                queryWrapper.eq("interview_status", interviewCandidates.getInterviewStatus());
            }
            if (interviewCandidates.getInterviewResult() != null) {
                queryWrapper.eq("interview_result", interviewCandidates.getInterviewResult());
            }
            if (interviewCandidates.getGender() != null) {
                queryWrapper.eq("gender", interviewCandidates.getGender());
            }
        }
        
        // 创建分页对象
        Page<InterviewCandidates> page = new Page<>(pageNum, pageSize);
        
        // 执行分页查询
        return interviewCandidatesMapper.selectPage(page, queryWrapper);
    }
}
